package consoletext

import (
	"strconv"
	"strings"
)

const (
	Black     = 30
	Red       = 31
	Green     = 32
	Yellow    = 33
	Blue      = 34
	Purple    = 35
	LightBlue = 36
	White     = 37
)

func ColorText(color int, text string) string {
	return "\x1b[" + strconv.Itoa(color) + "m" + text + "\x1b[0m"
}

type Format struct {
	Color      int
	Background int
	Highlight  bool
	Underline  bool
	Blink      bool
}

func FormatText(format Format, text string) string {
	f := []string{}
	if format.Color > 0 {
		f = append(f, strconv.Itoa(format.Color))
	}
	if format.Background > 0 {
		f = append(f, strconv.Itoa(format.Background+10))
	}
	if format.Highlight {
		f = append(f, "1")
	}
	if format.Underline {
		f = append(f, "4")
	}
	if format.Blink {
		f = append(f, "5")
	}
	return "\x1b[" + strings.Join(f, ";") + "m" + text + "\x1b[0m"
}
